package com.xyy.saas.payment.adpater.jdCredit.enums;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

/**
 * 京东金融支付 交易状态
 */
public enum JdCreditPayStatusEnum {

    UNPAY("UNPAY", "待支付"),
    PROCESS("PROCESS", "处理中"),
    PAYING("PAYING", "支付处理中"),
    PAID("PAID", "已支付"),
    CANCEL("CANCEL", "取消"),
    FAIL("FAIL", "失败");

    private String code;
    private String desc;

    private static Map<String, JdCreditPayStatusEnum> code2Enum;

    public static Map<String, String> statusConverter = new HashMap<>();


    static {
        code2Enum = Arrays.asList(values()).stream().collect(Collectors.toMap(JdCreditPayStatusEnum::getCode, UnaryOperator.identity()));
        statusConverter.put(JdCreditPayStatusEnum.PAYING.getCode(),"PROCESSING");
        statusConverter.put(JdCreditPayStatusEnum.PAID.getCode(),"FINISHED");
        statusConverter.put(JdCreditPayStatusEnum.PROCESS.getCode(),"PROCESSING");
        statusConverter.put(JdCreditPayStatusEnum.CANCEL.getCode(),"CANCELED");
        statusConverter.put(JdCreditPayStatusEnum.FAIL.getCode(),"FAILED");
    }

    JdCreditPayStatusEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String convertPayStatus(String code) {
        return statusConverter.get(code);
    }
    public static JdCreditPayStatusEnum getEnum(String code){
        return code2Enum.get(code);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

}
